﻿using System.ComponentModel;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using PropertyChanged;

namespace FFmpegVideoClip.Lib.AdvancedFragmentProcessor
{
    [AddINotifyPropertyChangedInterface]
    public class ParametersSign : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;
        protected void OnPropertyChanged(PropertyChangedEventArgs eventArgs) { this.PropertyChanged?.Invoke(this, eventArgs); }
        private static readonly PropertyChangedEventArgs ParameterEventArgs = new(nameof(Parameter));
        /// <summary>
        /// 输入公约签名
        /// </summary>
        public const string InputSignNamePattern = "#*Input";
        /// <summary>
        /// 输入公约签名
        /// </summary>
        public const string InputSignName = "#*Input*#";
        /// <summary>
        /// 多输入公约签名_FFmpeg
        /// </summary>
        public const string InputSignNames_FFmpeg = "#*Inputs_FFmpeg*#";
        /// <summary>
        /// 多输入公约签名_FFmpeg
        /// </summary>
        public const string InputSCount = "#*InputSCount*#";
        /// <summary>
        /// 输出公约签名
        /// </summary>
        public const string OutputSignName = "#*Output*#";
        /// <summary>
        /// 开始时间公约签名
        /// </summary>
        public const string STime = "#*STime*#";
        /// <summary>
        /// 结束时间公约签名
        /// </summary>
        public const string ETime = "#*ETime*#";
        public const string InputInfoPattern = "#*InputInfo_";
        /// <summary>
        /// 公约参数项
        /// </summary>
        public const string Sign = "#**#";

        /// <summary>
        /// 公约空参数值
        /// </summary>
        public const string EmptyParameter = "#";

        /// <summary>
        /// LogInfo文件公约后缀名
        /// </summary>
        public const string LogInfoExtension = ".LogInfo";


        public string SignName { get; set; } = string.Empty;
        public string ShowName { get; set; } = string.Empty;

        [XmlIgnore, JsonIgnore]
        private string _Parameter = string.Empty;
        /// <summary>
        /// 参数值
        /// <para>
        /// 在通过界面赋值的输入变量中，该值是一个代表流畅队列中索引的值，需通过该值去对应的队列中取实际的输入路径
        /// </para>
        /// </summary>

        [DoNotNotify] public string Parameter 
        {
            get => _Parameter;
            set
            {
                if (_Parameter.Equals(value))
                    return;
                _Parameter = value;
                if (SignName.StartsWith(InputSignNamePattern) && int.TryParse(value, out int v))
                    ParameterIndex = v;
                OnPropertyChanged(ParameterEventArgs);
            }
        }
        public int ParameterIndex { get; set; } = 0;
        [XmlIgnore, JsonIgnore] public bool HasParameter = false;
        
        public void UpdateIndexValue()
        {
            if (SignName.StartsWith(InputSignNamePattern) && int.TryParse(_Parameter, out int v))
                ParameterIndex = v;
        }

        public ParametersSign Clone() => (ParametersSign)MemberwiseClone();

    }

   

}
